/*
** my_files_detailed.c for my_files_detailed in /home/comet_a//afs/local/sys_unix/my_ls/tp_stat
** 
** Made by alexandre comet
** Login   <comet_a@epitech.net>
** 
** Started on  Fri Dec  2 19:07:19 2011 alexandre comet
** Last update Sun Dec  4 21:18:23 2011 alexandre comet
*/

#include        <stdlib.h>
#include        <sys/types.h>
#include        <dirent.h>
#include        <unistd.h>
#include        "my_ls.h"

int             main(int ac, char **av)
{
  if (ac == 1)
    no_options();
  else if (ac == 2 && !my_strcmp(av[1], "-l"))
    option_l();
  else if (ac == 2 && !my_strcmp(av[1], "-a"))
    option_a();
  else if (av[1] != "-a" )
   my_putstr("USAGE : ./my_ls [-option]\n");
  return (0);
}

int		no_options()
{
  DIR           *dirp;
  struct dirent *d;
  const char    *name;

  name = ".";
  dirp = opendir(name);
  if (dirp == NULL)
    exit (0);
  d = readdir(dirp);
  if (d == NULL)
    exit (0);
  my_putstr(d->d_name);
  my_putchar(' ');
  while ((d = readdir(dirp)) != NULL)
    {
      if (d == NULL)
	exit (0);
      if (d->d_name[0] != '.')
	{
	  my_putstr(d->d_name);
	  my_putchar(' ');
	}
    }
  my_putchar('\n');
  return (0);
}

int		option_l()
{
  DIR           *dirp;
  struct dirent *d;
  //  struct stat   *s;
  const char    *name;

  name = ".";
  dirp = opendir(name);
  if (dirp == NULL)
    exit (0);
  d = readdir(dirp);
  if (d == NULL)
    exit (0);
  my_putstr(d->d_name);
  my_putchar('\n');
  while ((d = readdir(dirp)) != NULL)
    {
      if (d == NULL)
        exit (0);
      my_putstr(d->d_name);
      my_putchar('\n');
    }
  return (0);
}

int		option_a()
{
  DIR           *dirp;
  struct dirent *d;
  //  struct stat   *s;
  const char    *name;

  name = ".";
  dirp = opendir(name);
  if (dirp == NULL)
    exit (0);
  d = readdir(dirp);
  if (d == NULL)
    exit (0);
  my_putstr(d->d_name);
  my_putchar(' ');
  while ((d = readdir(dirp)) != NULL)
    {
      if (d == NULL)
        exit (0);
          my_putstr(d->d_name);
          my_putchar(' ');
    }
  my_putchar('\n');
  return (0);
}
